#include"comm.h"

static int Commshm(int size, int flags)
{   
    printf("diary!\n");
    key_t _key = ftok(PATHNAME, PROJ_ID);
    if(_key < 0)
    {
        perror("ftok");
        return -1;
    }
    int shmid = 0;
    shmid = shmget(_key, size, flags);
    if(shmid < 0)
    {
        perror("shmget");
        return -2;
    }
    return shmid;
}

int destroyshm(int shmid)
{
    if(shmctl(shmid, IPC_RMID, NULL) < 0)
    {
        perror("shmctl");
        return -1;
    }
    return 0;
}

int Getshm(int size)
{
    return Commshm(size, IPC_CREAT);
}

int Createshm(int size)//返回shmid
{
    return Commshm(size, IPC_CREAT|00666);
}
